﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using CRM_SMS_MARKETING.PL.Message;
using CRM_SMS_MARKETING.PL.System_Management;
using CRM_SMS_MARKETING.PL.Customer;
using CRM_SMS_MARKETING.PL.Customer_Care;
using Crystal_Report_WithoutDB;
using System.Threading;
using CRM_SMS_MARKETING.BL;
//using SmsControl;

namespace CRM_SMS_MARKETING
{
    public partial class frmMain : DevExpress.XtraEditors.XtraForm
    {
        string User;
        string UserType;
        Thread thread;
        public frmMain(string _User, string _UserType)
        {
            InitializeComponent();
            User = _User;
            UserType=_UserType;
        }
        Form checkexist(string fName)
        {
            foreach (Form f in this.MdiChildren)
            {
                if (f.Name == fName)
                    return f;
            }
            return null;
        }
        public void Admin()
        {
            btnUser.Enabled = true;
        }

        public void NormalUser()
        {
            btnUser.Enabled = false;
        }
        private void btnCompose_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            Form f = checkexist("frmComposeMessage");
            if (f != null)
                f.Activate();
            else
            {
                frmComposeMessage frm = new frmComposeMessage(list_Modem);
                frm.Name = "frmComposeMessage";
                frm.MdiParent = this;
                frm.Show();
            }
        }

        private void btnTemplate_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            Form f = checkexist("frmTemplate");
            if (f != null)
                f.Activate();
            else
            {
                frmTemplate frm = new frmTemplate();
                frm.Name = "frmTemplate";
                frm.MdiParent = this;
                frm.Show();
            }
        }

        private void btnUser_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            Form f = checkexist("frmUser");
            if (f != null)
                f.Activate();
            else
            {
                frmUser frm = new frmUser(User);
                frm.Name = "frmUser";
                frm.MdiParent = this;
                frm.Show();
            }
           
        }

        private void btnConnectModem_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            Form f = checkexist("frmModems");
            if (f != null)
                f.Activate();
            else
            {
                frmModems frm = new frmModems(list_Modem);
                frm.Name = "frmModems";
                frm.MdiParent = this;
                frm.Show();
            }
        }

        private void btnContact_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            Form f = checkexist("frmCustomer");
            if (f != null)
                f.Activate();
            else
            {
                frmCustomer frm = new frmCustomer(User,UserType);
                frm.Name = "frmCustomer";
                frm.MdiParent = this;
                frm.Show();
            }
        }

        private void btnSMSManagement_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            Form f = checkexist("frmMessageManagement");
            if (f != null)
                f.Activate();
            else
            {
                frmMessageManagement frm = new frmMessageManagement();
                frm.Name = "frmMessageManagement";
                frm.MdiParent = this;
                frm.Show();
            }
        }
        private void frmMain_Load(object sender, EventArgs e)
        {
            timer1.Start();
            // filling the combo box with data
         
            List<String> ListSkin = new List<string>();
            #region
            ListSkin.Add("DevExpress Style");
            ListSkin.Add("Caramel");
            ListSkin.Add("Money Twins");
            ListSkin.Add("Lilian");
            ListSkin.Add("DevExpress Dark Style");
            ListSkin.Add("iMaginary");
            ListSkin.Add("Black");
            ListSkin.Add("Blue");
            #endregion

            for (int i = 0; i < ListSkin.Count; i++)
            {
              
                repositoryItemComboBox2.Items.Add(ListSkin[i].ToString());  
              
            }


                // disabling the text editor of the combo box 
            // specifying the number of lines in the dropdown window 
            repositoryItemComboBox1.DropDownRows = ListSkin.Count;
            // initializing the combo box with the first available font name 
            barEditSkin.EditValue = ListSkin[0];
        }

        private void barEditSkin_EditValueChanged(object sender, EventArgs e)
        {
            defaultLookAndFeel1.LookAndFeel.SkinName = barEditSkin.EditValue.ToString();
        }

        List<SmsControl.SmsControl> list_Modem = new List<SmsControl.SmsControl>();

        private void btnUserAccount_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {

        }

        private void btnSpecialDay_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            Form f = checkexist("frmSpecialDay");
            if (f != null)
                f.Activate();
            else
            {
                frmSpecialDay frm = new frmSpecialDay();
                frm.Name = "frmSpecialDay";
                frm.MdiParent = this;
                frm.Show();
            }
        }

        private void btnReport_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {

            Form f = checkexist("frmReportMain");
            if (f != null)
                f.Activate();
            else
            {
                frmReportMain frm = new frmReportMain();
                frm.Name = "frmReportMain";
                frm.MdiParent = this;
                frm.Show();
            }
            
        }

        private void btnBirthday_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            Form f = checkexist("frmBirthday");
            if (f != null)
                f.Activate();
            else
            {
                frmBirthday frm = new frmBirthday();
                frm.Name = "frmBirthday";
                frm.MdiParent = this;
                frm.Show();
            }
        }

        private void btnPromotion_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            Form f = checkexist("frmPromotion");
            if (f != null)
                f.Activate();
            else
            {
                frmPromotion frm = new frmPromotion();
                frm.Name = "frmPromotion";
                frm.MdiParent = this;
                frm.Show();
            }
        }

        private void btnCustomer_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            Form f = checkexist("frmCustomer");
            if (f != null)
                f.Activate();
            else
            {
                frmCustomer frm = new frmCustomer(User, UserType);
                frm.Name = "frmCustomer";
                frm.MdiParent = this;
                frm.Show();
            }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {

            BLLCustomer bllCustomer = new BLLCustomer();
            bllCustomer.CustomerBirthDay();
            bllCustomer.CustomerEvent();
        }
    }
}